package com.Txunda.fxw.ui.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.Txunda.fxw.R;
import com.Txunda.fxw.ui.adapter.base.BaseRecyclerViewAdapter;
import com.Txunda.fxw.ui.adapter.base.BaseRecyclerViewHolder;

import java.util.Map;

import butterknife.BindView;

/**
 * 创建时间：2018/11/14 9:53
 * 文件名称：SmallSizedClassifyAdapter
 * 作    者：Hzj
 * 描    述：
 * 注    意：
 * 修    改：
 * 参    考：
 * 出    自：书山府科技 android
 **/
public class SmallSizedClassifyAdapter extends BaseRecyclerViewAdapter<Map<String, String>, SmallSizedClassifyAdapter.SmallVh> {

    private int selectedPosition = 0;

    public SmallSizedClassifyAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public SmallVh onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new SmallVh(inflateItemView(viewGroup, R.layout.item_small_sized_classify_rv));
    }

    public void setSelectedPosition(int selectedPosition) {
        this.selectedPosition = selectedPosition;
        notifyDataSetChanged();
    }

    class SmallVh extends BaseRecyclerViewHolder<Map<String, String>> {
        @BindView(R.id.classify_name_tv)
        TextView classifyNameTv;
        @BindView(R.id.classify_selected_view)
        View classifySelectedView;

        public SmallVh(View itemView) {
            super(itemView);
        }

        @Override
        public void setData(Map<String, String> item, int position) {
            classifyNameTv.setText(item.get("name"));
            if (selectedPosition == position) {
                classifyNameTv.setTextColor(ContextCompat.getColor(mContext, R.color.colorAccent));
                classifySelectedView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.colorAccent));
            } else {
                classifyNameTv.setTextColor(ContextCompat.getColor(mContext, R.color.text_black));
                classifySelectedView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white));
            }
        }

        @Override
        public void setViewOnClick(final int position, final Map<String, String> item) {
            super.setViewOnClick(position, item);
            classifyNameTv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    adapterViewClickListener.onViewClick(v, position, item);
                }
            });
        }
    }
}
